package BLL.User;

import BIZ.statementofncomeBiz;
import BIZ.totalFeeBiz;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

@WebServlet(name = "RefundCharge", value = "/RefundCharge")
public class RefundCharge extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public RefundCharge() {
        super();
    }

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        HttpSession session = request.getSession();

        //获取表单递送的用户退费余额
        String money = new String(request.getParameter("money").getBytes(StandardCharsets.UTF_8));

        //从session获取用户信息
        String UserName = (String) session.getAttribute("UserName");

        statementofncomeBiz statementofncomeBiz = new statementofncomeBiz();
        totalFeeBiz totalFeeBiz = new totalFeeBiz();

        //进行退费
        String newbalance = statementofncomeBiz.Refundorcost(UserName, money);

        //将退费后的总数额递到total
        int x = totalFeeBiz.subincome(money);

        //将退费后的余额存入session
        session.setAttribute("Balance", newbalance);


    }

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

}
